<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二手交易平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #1a1a1a;
            --secondary: #333333;
            --accent: #666666;
            --light: #f5f5f5;
            --white: #ffffff;
            --dark: #000000;
            --light-gray: #e0e0e0;
            --medium-gray: #999999;
            --success: #28a745;
            --error: #dc3545;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4e7eb 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            display: flex;
            max-width: 1200px;
            width: 100%;
            background: var(--white);
            border-radius: 20px;
            overflow: hidden;
            box-shadow: var(--shadow);
            animation: fadeIn 1s ease-out;
            border: 1px solid var(--light-gray);
        }

        /* 功能特性区域 */
        .features-section {
            flex: 1;
            background: linear-gradient(135deg, var(--dark) 0%, #1a1a1a 100%);
            color: var(--light);
            padding: 50px 40px;
            position: relative;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            justify-content: center;
            border-right: 1px solid rgba(255, 255, 255, 0.05);
        }

        .features-section::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
            transform: rotate(30deg);
        }

        .features-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 25px;
            position: relative;
            z-index: 2;
        }

        .feature-card {
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 25px;
            transition: var(--transition);
            border: 1px solid rgba(255,255,255,0.05);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .feature-card:hover {
            transform: translateY(-5px);
            background: rgba(255, 255, 255, 0.08);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }

        .feature-icon {
            width: 50px;
            height: 50px;
            background: var(--secondary);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 20px;
            font-size: 20px;
            color: var(--light);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
        }

        .feature-card h3 {
            font-size: 18px;
            margin-bottom: 12px;
            font-weight: 600;
            color: var(--light);
        }

        .feature-card p {
            font-size: 14px;
            line-height: 1.6;
            opacity: 0.8;
            color: var(--medium-gray);
        }

        /* 表单区域 */
        .form-section {
            flex: 1;
            padding: 50px 40px;
            position: relative;
            display: flex;
            flex-direction: column;
            justify-content: center;
            background: var(--white);
        }

        .form-container {
            max-width: 400px;
            width: 100%;
            margin: 0 auto;
        }

        .logo {
            text-align: center;
            margin-bottom: 40px;
        }

        .logo h1 {
            font-size: 32px;
            color: var(--dark);
            margin-bottom: 8px;
            letter-spacing: -0.5px;
        }

        .logo p {
            color: var(--medium-gray);
            font-size: 16px;
            font-weight: 300;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 24px;
            position: relative;
        }

        .form-control {
            width: 100%;
            height: 52px;
            padding: 0 20px;
            border: 1px solid var(--light-gray);
            border-radius: 10px;
            font-size: 15px;
            transition: var(--transition);
            background-color: var(--white);
            color: var(--dark);
            outline: none;
        }

        .form-control:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px rgba(102, 102, 102, 0.1);
        }

        .form-control::placeholder {
            color: var(--medium-gray);
            font-weight: 300;
        }

        .btn {
            width: 100%;
            height: 52px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            letter-spacing: 0.5px;
        }

        .btn-dark {
            background: var(--dark);
            color: var(--white);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .btn-dark:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
            background: #111;
        }

        .auth-link {
            text-align: center;
            margin-top: 20px;
            color: var(--medium-gray);
            font-size: 14px;
        }

        .auth-link a {
            color: var(--dark);
            text-decoration: none;
            font-weight: 500;
            margin-left: 5px;
            transition: var(--transition);
            border-bottom: 1px solid transparent;
        }

        .auth-link a:hover {
            color: var(--dark);
            border-bottom: 1px solid var(--dark);
        }

        .agreement {
            margin: 20px 0;
            font-size: 13px;
            color: var(--medium-gray);
            display: flex;
            align-items: flex-start;
        }

        .agreement input {
            margin-top: 3px;
            margin-right: 10px;
            accent-color: var(--dark);
        }

        .highlight {
            color: var(--dark);
            font-weight: 500;
            cursor: pointer;
            text-decoration: underline;
        }

        /* 错误提示 */
        .error-message {
            color: var(--error);
            font-size: 13px;
            margin-top: 5px;
            display: none;
            font-weight: 400;
        }

        /* 响应消息 */
        .response-message {
            padding: 15px;
            border-radius: 10px;
            margin: 15px 0;
            text-align: center;
            display: none;
            font-size: 14px;
            font-weight: 500;
        }

        .success {
            background-color: rgba(40, 167, 69, 0.08);
            border: 1px solid var(--success);
            color: var(--success);
        }

        .error {
            background-color: rgba(220, 53, 69, 0.08);
            border: 1px solid var(--error);
            color: var(--error);
        }

        /* 动画 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes shake {
            0%, 100% {transform: translateX(0);}
            10%, 30%, 50%, 70%, 90% {transform: translateX(-5px);}
            20%, 40%, 60%, 80% {transform: translateX(5px);}
        }

        .shake {
            animation: shake 0.5s;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .container {
                flex-direction: column;
                max-width: 600px;
            }

            .features-section {
                order: 2;
                padding: 30px 20px;
            }

            .form-section {
                order: 1;
                padding: 40px 20px;
            }

            .features-grid {
                grid-template-columns: 1fr;
            }
        }

        /* 高级装饰元素 */
        .decoration-line {
            position: absolute;
            background: var(--light-gray);
            z-index: 0;
        }

        .line-1 {
            top: 30%;
            left: 0;
            width: 100%;
            height: 1px;
            opacity: 0.3;
        }

        .line-2 {
            top: 60%;
            left: 0;
            width: 100%;
            height: 1px;
            opacity: 0.3;
        }

        .decoration-dot {
            position: absolute;
            background: var(--light-gray);
            border-radius: 50%;
            z-index: 0;
            opacity: 0.2;
        }

        .dot-1 {
            width: 8px;
            height: 8px;
            top: 30%;
            right: 30px;
        }

        .dot-2 {
            width: 6px;
            height: 6px;
            top: 60%;
            left: 40px;
        }
    </style>
</head>
<body>
<!-- 注册页面 -->
<div class="container" id="registerPage">
    <!-- 功能特性区域 -->
    <div class="features-section">
        <div class="decoration-line line-1"></div>
        <div class="decoration-line line-2"></div>
        <div class="decoration-dot dot-1"></div>
        <div class="decoration-dot dot-2"></div>

        <h2 style="font-size: 28px; margin-bottom: 40px; text-align: center; font-weight: 600; position: relative; z-index: 3; color: var(--light);">加入我们的优势</h2>

        <div class="features-grid">
            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3>安全交易保障</h3>
                <p>平台提供资金托管服务，确保交易安全无忧，买卖双方权益得到充分保障。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-wallet"></i>
                </div>
                <h3>零手续费政策</h3>
                <p>免费发布商品，交易过程不收取任何手续费，最大化您的交易收益。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-shipping-fast"></i>
                </div>
                <h3>高效物流系统</h3>
                <p>与主流物流公司合作，一键发货，全国覆盖，物流状态实时可查。</p>
            </div>

            <div class="feature-card">
                <div class="feature-icon">
                    <i class="fas fa-chart-line"></i>
                </div>
                <h3>商品推广支持</h3>
                <p>优质商品可获得平台免费推广，增加曝光率，提高成交机会。</p>
            </div>
        </div>

        <div class="feature-card" style="margin-top: 30px; background: rgba(40, 167, 69, 0.08);">
            <h3 style="color: var(--success);"><i class="fas fa-gem"></i> 会员专属权益</h3>
            <p>升级为会员可享受<span style="color: var(--success); font-weight: 600;">优先客服、更高曝光率、专属优惠</span>等特权服务。</p>
        </div>
    </div>

    <!-- 注册表单区域 -->
    <div class="form-section">
        <div class="form-container">
            <div class="logo">
                <h1>加入二手易购</h1>
                <p>开启您的二手交易之旅</p>
            </div>

            <!-- 响应消息区域 -->
            <div class="response-message" id="responseMessage"></div>

            <div class="form-group">
                <input type="text" class="form-control" id="regUsername" placeholder="设置用户名" required>
                <div class="error-message" id="usernameError">用户名不能为空</div>
            </div>

            <div class="form-group">
                <input type="password" class="form-control" id="regPassword" placeholder="设置密码" required>
                <div class="error-message" id="passwordError">密码长度至少6位</div>
            </div>

            <div class="form-group">
                <input type="password" class="form-control" id="regConfirmPassword" placeholder="确认密码" required>
                <div class="error-message" id="confirmPasswordError">两次输入的密码不一致</div>
            </div>

            <div class="form-group">
                <input type="tel" class="form-control" id="regPhone" placeholder="手机号码" required>
                <div class="error-message" id="phoneError">请输入有效的手机号码</div>
            </div>

            <div class="agreement">
                <input type="checkbox" id="agreement">
                <label>
                    我已阅读并同意<span class="highlight">《用户协议》</span>和<span class="highlight">《隐私政策》</span>
                </label>
                <div class="error-message" id="agreementError" style="margin-top: 5px;">请阅读并同意用户协议</div>
            </div>

            <button class="btn btn-dark" id="registerBtn">
                注册账号
            </button>

            <div class="auth-link">
                已有账号? <a href="login.html">立即登录</a>
            </div>
        </div>
    </div>
</div>

<script>
    // 表单验证函数
    function validateForm() {
        let isValid = true;
        const username = document.getElementById('regUsername').value.trim();
        const password = document.getElementById('regPassword').value;
        const confirmPassword = document.getElementById('regConfirmPassword').value;
        const phone = document.getElementById('regPhone').value.trim();
        const agreement = document.getElementById('agreement').checked;

        // 重置错误信息
        document.querySelectorAll('.error-message').forEach(el => {
            el.style.display = 'none';
        });

        // 验证用户名
        if (!username) {
            showError('usernameError', '用户名不能为空');
            isValid = false;
        }

        // 验证密码
        if (password.length < 6) {
            showError('passwordError', '密码长度至少6位');
            isValid = false;
        }

        // 验证确认密码
        if (password !== confirmPassword) {
            showError('confirmPasswordError', '两次输入的密码不一致');
            isValid = false;
        }

        // 验证手机号
        const phoneRegex = /^1[3-9]\d{9}$/;
        if (!phoneRegex.test(phone)) {
            showError('phoneError', '请输入有效的手机号码');
            isValid = false;
        }

        // 验证协议
        if (!agreement) {
            showError('agreementError', '请阅读并同意用户协议');
            isValid = false;
        }

        return isValid;
    }

    // 显示错误信息
    function showError(elementId, message) {
        const errorElement = document.getElementById(elementId);
        errorElement.textContent = message;
        errorElement.style.display = 'block';

        // 找到对应的输入框或复选框
        let inputField;
        switch(elementId) {
            case 'usernameError':
                inputField = document.getElementById('regUsername');
                break;
            case 'passwordError':
                inputField = document.getElementById('regPassword');
                break;
            case 'confirmPasswordError':
                inputField = document.getElementById('regConfirmPassword');
                break;
            case 'phoneError':
                inputField = document.getElementById('regPhone');
                break;
            case 'agreementError':
                inputField = document.getElementById('agreement');
                break;
        }

        if (inputField) {
            inputField.classList.add('shake');
            setTimeout(() => {
                inputField.classList.remove('shake');
            }, 500);
        }
    }

    // 显示响应消息
    function showResponseMessage(message, isSuccess) {
        const responseElement = document.getElementById('responseMessage');
        responseElement.textContent = message;
        responseElement.className = isSuccess ? 'response-message success' : 'response-message error';
        responseElement.style.display = 'block';

        // 5秒后自动隐藏
        setTimeout(() => {
            responseElement.style.display = 'none';
        }, 5000);
    }

    // 注册按钮事件
    document.getElementById('registerBtn').addEventListener('click', async function() {
        // 验证表单
        if (!validateForm()) {
            return;
        }

        // 收集表单数据
        const userData = {
            uName: document.getElementById('regUsername').value.trim(),
            uPassword: document.getElementById('regPassword').value,
            uPhoneNumber: document.getElementById('regPhone').value.trim(),
            uIsAdmin: false,
            uBalance: 0
        };

        // 更新按钮状态
        const originalText = this.innerHTML;
        this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 注册中...';
        this.disabled = true;

        try {
            // 发送注册请求到后端
            const response = await fetch('/user/register', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(userData)
            });

            // 解析响应
            const result = await response.text();

            if (response.ok) {
                // 注册成功
                showResponseMessage('注册成功！即将跳转到登录页面...', true);
                this.innerHTML = '<i class="fas fa-check"></i> 注册成功';

                // 保存用户数据到localStorage（可选）
                localStorage.setItem('registeredUser', JSON.stringify(userData));

                // 2秒后跳转到登录页面
                setTimeout(() => {
                    window.location.href = 'login.html';
                }, 2000);
            } else {
                // 注册失败
                throw new Error(result || '注册失败，请重试');
            }
        } catch (error) {
            // 处理错误
            showResponseMessage(error.message, false);
            this.innerHTML = originalText;
            this.disabled = false;
        }
    });

    // 输入框实时验证
    document.getElementById('regUsername').addEventListener('blur', function() {
        if (!this.value.trim()) {
            showError('usernameError', '用户名不能为空');
        } else if (this.value.trim().length < 3) {
            showError('usernameError', '用户名至少需要3个字符');
        } else {
            document.getElementById('usernameError').style.display = 'none';
        }
    });

    document.getElementById('regPassword').addEventListener('blur', function() {
        if (this.value.length < 6) {
            showError('passwordError', '密码长度至少6位');
        } else {
            document.getElementById('passwordError').style.display = 'none';
        }
    });

    document.getElementById('regConfirmPassword').addEventListener('blur', function() {
        const password = document.getElementById('regPassword').value;
        if (this.value !== password) {
            showError('confirmPasswordError', '两次输入的密码不一致');
        } else {
            document.getElementById('confirmPasswordError').style.display = 'none';
        }
    });

    document.getElementById('regPhone').addEventListener('blur', function() {
        const phoneRegex = /^1[3-9]\d{9}$/;
        if (!phoneRegex.test(this.value.trim())) {
            showError('phoneError', '请输入有效的手机号码');
        } else {
            document.getElementById('phoneError').style.display = 'none';
        }
    });

    document.getElementById('agreement').addEventListener('change', function() {
        if (this.checked) {
            document.getElementById('agreementError').style.display = 'none';
        }
    });

    // 调试：确认所有元素加载完成
    document.addEventListener('DOMContentLoaded', function() {
        console.log("页面加载完成 - 高级黑白色调注册页面");
    });
</script>
</body>
</html>